+2005-08-29 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-format.c: (each_babl_format_destroy), (format_new),
+ (create_name), (babl_format_new): New API, name is now a key/value
+ pair, and if not set the name will be autogenerated.
+ * babl/base/model-rgb.c,
+ * babl/base/model-ycbcr.c,
+ * extensions/CIE-Lab.c,
+ * extensions/naive-CMYK.c,
+ * tests/Makefile.am,
+ * tests/float_to_u8.c,
+ * tests/grayscale_to_rgb.c,
+ * tests/rgb_to_bgr.c,
+ * tests/rgb_to_lab_to_rgb.c,
+ * tests/rgb_to_ycbcr.c,
+ * tests/rgb_to_ycbcr_to_rgb.c,
+ * tests/u8_to_float.c: update to new API.
+
2005-08-29 Øyvind Kolås <pippin@gimp.org>
* babl/babl-db.h: Do nor warn about collision during db_insert
static int
each_babl_format_destroy (Babl *babl,
- void *data)
+ void *data)
{
babl_free (babl->format.from);
babl_free (babl->format.to);
static Babl *
format_new (const char *name,
- int id,
- int planar,
- int components,
- BablModel *model,
- BablComponent **component,
- BablSampling **sampling,
- BablType **type)
+ int id,
+ int planar,
+ int components,
+ BablModel *model,
+ BablComponent **component,
+ BablSampling **sampling,
+ BablType **type)
{
Babl *babl;
return babl;
}
+
+static char buf[512]="";
+
+static const char *
+create_name (BablModel *model,
+ int components,
+ BablComponent **component,
+ BablType **type)
+{
+ char *p = &buf[0];
+
+ sprintf (p, "%s ", model->instance.name);
+ p+=strlen (model->instance.name) + 1;
+
+ while (components--)
+ {
+ sprintf (p, "(%s as %s) ",
+ (*component)->instance.name,
+ (*type)->instance.name);
+ p+=strlen ((*component)->instance.name) +
+ strlen ((*type)->instance.name ) + strlen("( as ) ");
+ component++;
+ type++;
+ }
+ return buf;
+}
+
Babl *
-babl_format_new (const char *name,
- ...)
+babl_format_new (void *first_arg,
+ ...)
{
va_list varg;
Babl *babl;
BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1);
BablType *current_type = (BablType*) babl_type_id (BABL_U8);
- const char *arg = name;
-
- va_start (varg, name);
+ char *name = NULL;
+ void *arg = first_arg;
+ va_start (varg, first_arg);
while (1)
{
- arg = va_arg (varg, char *);
- if (!arg)
- break;
-
-
if (BABL_IS_BABL (arg))
{
Babl *babl = (Babl*)arg;
{
id = va_arg (varg, int);
}
+
+ else if (!strcmp (arg, "name"))
+ {
+ name = va_arg (varg, char *);
+ }
else if (!strcmp (arg, "packed"))
{
{
babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
}
+
+ arg = va_arg (varg, char *);
+ if (!arg)
+ break;
}
va_end (varg);
+ babl = format_new (name?name:create_name (model, components, component, type),
+ id,
+ planar, components, model,
+ component, sampling, type);
+
+ {
+ Babl *ret;
+ ret = db_insert (babl);
- babl = format_new (name, id,
- planar, components, model,
- component, sampling, type);
+ if (ret==babl)
+ {
+ return babl;
+ }
+ else
+ {
+ each_babl_format_destroy (babl, NULL);
+ return ret;
+ }
+ }
-
- if (db_insert (babl) == babl)
- {
- return babl;
- }
- else
- {
- each_babl_format_destroy (babl, NULL);
- return NULL;
- }
}
BABL_CLASS_TEMPLATE (babl_format)
formats (void)
{
babl_format_new (
- "srgb",
+ "name", "srgb",
"id", BABL_SRGB,
babl_model_id (BABL_RGB_GAMMA_2_2),
babl_type_id (BABL_U8),
NULL);
babl_format_new (
- "srgba",
+ "name", "srgba",
"id", BABL_SRGBA,
babl_model_id (BABL_RGBA_GAMMA_2_2),
babl_type_id (BABL_U8),
NULL);
babl_format_new (
- "rgba-float",
+ "name", "rgba-float",
"id", BABL_RGBA_FLOAT,
babl_model_id (BABL_RGBA),
babl_type_id (BABL_FLOAT),
NULL);
babl_format_new (
- "rgba-double",
+ "name", "rgba-double",
"id", BABL_RGBA_DOUBLE,
babl_model_id (BABL_RGBA),
babl_type_id (BABL_DOUBLE),
NULL);
babl_format_new (
- "rgb-float",
+ "name", "rgb-float",
"id", BABL_RGB_FLOAT,
babl_model_id (BABL_RGB),
babl_type_id (BABL_FLOAT),